%==========================================================================
%=  This file is part of the Sound Restoration Project
%=  (c) Copyright Industrial Mathematics Institute
%=                University of South Carolina, Department of Mathematics
%=  ALL RIGHTS RESERVED
%=
%=  Author: Borislav Karaivanov
%==========================================================================

%==========================================================================
% List of the files on which this procedure depends:
%
% none
%
%==========================================================================

%==========================================================================
% The function "writeToLogFile" writes a given string to a log text file
% whose name is specified using a global variable.
% INPUT: "logFileName" is the name (including a full directory path) of the
% log text file where the given string is to be written.
% "outStr" is a string to be written to the log text file.
% OUTPUT: "logFileName" returns the name (including a full directory path)
% of the log text file where the given string is written.
%==========================================================================
function logFileName = writeToLogFile(logFileName, outStr)

% Open the log file currently in use.
fid = fopen(logFileName, 'a');
if (fid == -1)
    warning('SoundRestoration:writeToLogFile:CanNotAppendToLogFile', ...
        '(in writeToLogFile) unable to open the file %s for appending.\n', logFileName);
    fprintf(1, 'Unable to open the file %s for appending.\n', logFileName);
    return;
else
    fprintf(1, 'Writing to the log file %s.\n', logFileName);
end

% Write the given string.
fprintf(fid, '%s\n', outStr);

% Close the file.
fclose(fid);

return;
% end of the function "writeToLogFile"
